<?php 
/** 
 * 二叉树的镜像
 * 操作给定的二叉树，将其变换为源二叉树的镜像。 
 */
class TreeNode
{
    public $val;
    public $left = NULL;
    public $right = NULL;
    public function __construct($val)
    {
        $this->val = $val;
    }
}


/** 
 * 递归反转
 * @param [type] &$root [description]
 */
function Mirror(&$root)
{
    if ($root != null) {
    	Mirror($root->left);
		Mirror($root->right);
		$temp = $root->left;;
		$root->left = $root->right;
		$root->right = $temp;
    }
}

$node = new TreeNode(8);
$node->left = new TreeNode(6);
$node->left->left = new TreeNode(5);
$node->left->right = new TreeNode(7);
$node->right = new TreeNode(10);
$node->right->left = new TreeNode(9);
$node->right->right = new TreeNode(11);

Mirror($node);
var_dump($node);